<script setup>
import { toRefs, ref, onMounted } from 'vue';
import TDTDX from '@/assets/images/base-map/DX.png';
import Arcgis from '@/assets/images/base-map/arcgis图层.png';
import BiaoZhuTu from '@/assets/images/base-map/biaozhutu.png';
import LayerClose from '@/assets/images/base-map/layer-close.png';
import YingXiangTu from '@/assets/images/base-map/yingxiangtu.png';
import { TOGGLE_BASE_MAP, MAP_INIT_3d } from '@/pages/module-map/map-cesium-js/common-cesium.js';

const props = defineProps({
  toolbarRight: {
    type: String,
    default: '5.3125rem',
  },
});
const { toolbarRight } = toRefs(props);

const emit = defineEmits(['handleChangeIsBaseLayer']);
const baseMapName = ref({
  name: '影像图',
  img: YingXiangTu,
});

const baseMapList = [
  //基础底图
  {
    name: 'arcgis图层',
    img: Arcgis,
  },
  {
    name: '影像图',
    img: YingXiangTu,
  },
  {
    name: '标注图',
    img: BiaoZhuTu,
  },
  {
    name: '天地图地形',
    img: TDTDX,
  },
];

onMounted(() => {});

const changeBaseLayer = (item) => {
  const viewer = MAP_INIT_3d();

  if (item?.name === '影像图') {
    TOGGLE_BASE_MAP('TDT_YX', viewer);
  }

  if (item?.name === 'arcgis图层') {
    TOGGLE_BASE_MAP('ARCGIS', viewer);
  }

  if (item?.name === '标注图') {
    TOGGLE_BASE_MAP('TDT_ZJ', viewer);
  }

  if (item?.name === '天地图地形') {
    TOGGLE_BASE_MAP('TDT_DX', viewer);
  }

  baseMapName.value = item;
};

const handleChangeShow = () => {
  emit('handleChangeIsBaseLayer');
};
</script>
<template>
  <div class="map-base-layer absolute z-20" :style="{ right: toolbarRight }">
    <div class="line line-top-left"></div>
    <div class="line line-bottom-left"></div>
    <div class="line line-bottom-right"></div>
    <div class="bg"></div>
    <div class="content">
      <div class="top">
        <div class="bg-top"></div>
        <div class="text">基础底图</div>
        <div class="close-icon" @click="handleChangeShow()">
          <img :src="LayerClose" />
        </div>
      </div>
      <div class="box-content">
        <div class="layer-box p-7px">
          <div
            v-for="item in baseMapList"
            :key="item.name"
            class="layer-box-item"
            :class="baseMapName.name === item.name ? 'layer-box-item-active' : ''"
            @click="changeBaseLayer(item)"
          >
            <img :src="item.img" />
            <div>{{ item.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.map-base-layer {
  top: 10%;
  width: 260px;
  height: 250px;
  border-right: 2px solid rgb(38, 196, 251);
  border-left: 2px solid rgb(38, 196, 251);
  transition: 1s;
  .line {
    position: absolute;
    z-index: 2;
    width: 14px;
    height: 3px;
    background: rgba(38, 196, 251, 1);
  }
  .line-top-left {
    top: 0;
    left: 0;
  }
  .line-bottom-left {
    bottom: 0;
    left: 0;
  }
  .line-bottom-right {
    right: 0;
    bottom: 0;
  }
  .bg {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    background: rgba(0, 19, 26, 0.7);
    opacity: 1;
    backdrop-filter: blur(10px);
  }
  .content {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    color: rgba(255, 255, 255, 0.5);
    .top {
      width: 100%;
      height: 28px;
      padding-left: 13px;
      .text {
        position: absolute;
        z-index: 2;
        color: #fff;
        font-size: 14px;
        line-height: 28px;
      }

      .bg-top {
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
        width: 100%;
        height: 28px;
        background: linear-gradient(90.44deg, rgba(38, 196, 251, 1) 0%, rgba(0, 13, 59, 0.19) 100%);
        opacity: 0.5;
      }
      .close-icon {
        position: absolute;
        top: -12px;
        right: -12px;
        z-index: 1;
        cursor: pointer;
      }
      img {
        display: block;
        width: 32px;
        height: 32px;
      }
    }
    .layer-box {
      display: flex;
      flex-wrap: wrap;

      .layer-box-item {
        margin: 7px 6px 0 6px;
        text-align: center;
        cursor: pointer;
        img {
          width: 61px;
          height: 61px;
          border: 1px solid rgba(38, 198, 251, 0);
        }
        div {
          width: 62px;
          overflow: hidden;
          font-size: 12px;
          line-height: 26px;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
      .layer-box-item-active {
        img {
          border: 1px solid rgba(38, 196, 251, 1);
        }
        div {
          color: rgba(44, 199, 254, 1);
        }
      }
    }
  }
}
</style>
